import { HttpMrg } from "./Http";

export let GameData = {
  fishFarm: {}, //当前主屋，厨房，货摊，道路，鱼塘等级
  nowTask: 0, //当前任务
  is_withdraw: 0, //提现次数
  novice: 0, //新手引导
  fishData: [], // 钓鱼数据[{类型,时间状态}] -1未解锁 0解锁 1<= 不同鱼的类型
  redNumber: 0, //红包券
  money: 0, //钞票
  speedUpTimes: 0, //全体加速次数
  isContinuousLogin: 0,
  red_receive_log: {}, //是否领取
  piggy_bank_log: {}, //金额数据
  ad_conut: 0, //看广告次数
  offlineTime: 0, //离线时间
  kitchenData: {}, //厨房食材加工数据
  kitchen_stove: {}, //灶台解锁数据
  fish_list: [1,2,3], //解锁鱼类数据
  fish_stock: [1,2,3], //鱼库存
  fish_pond: [1,2,3], //鱼塘解锁数据
  fishing_num: 0, //钓鱼次数
};

export let GameConfigData = {
  fishFarmConfig: {}, //主屋，厨房，货摊，道路，鱼塘等级升级配置
  redConfig: {}, //红包数据
  loginDayNum: 0, //登录天数
  userName:"",
  orderData:{},
  fishTimeConfig: [
    {
      id: 1,
      name: "鲫鱼",
      time: 5,
      money: 0,
      profit: 100,
      reward: 0,
    },
    {
      id: 2,
      name: "鲫鱼",
      time: 5,
      money: 0,
      profit: 100,
      reward: 0,
    },
    {
      id: 3,
      name: "鲫鱼",
      time: 5,
      money: 0,
      profit: 100,
      reward: 0,
    },
    {
      id: 4,
      name: "鲫鱼",
      time: 60,
      money: 0,
      profit: 100,
      reward: 0,
    },
    {
      id: 5,
      name: "鲫鱼",
      time: 60,
      money: 0,
      profit: 100,
      reward: 0,
    },
    {
      id: 6,
      name: "鲫鱼",
      time: 60,
      money: 0,
      profit: 100,
      reward: 0,
    },
    {
      id: 7,
      name: "鲫鱼",
      time: 60,
      money: 0,
      profit: 100,
      reward: 0,
    },
    {
      id: 8,
      name: "鲫鱼",
      time: 60,
      money: 0,
      profit: 100,
      reward: 0,
    },
    {
      id: 9,
      name: "鲫鱼",
      time: 60,
      money: 0,
      profit: 100,
      reward: 0,
    },
    {
      id: 10,
      name: "鲫鱼",
      time: 60,
      money: 0,
      profit: 100,
      reward: 0,
    },
    {
      id: 11,
      name: "鲫鱼",
      time: 60,
      money: 0,
      profit: 100,
      reward: 0,
    },
    {
      id: 12,
      name: "鲫鱼",
      time: 60,
      money: 0,
      profit: 100,
      reward: 0,
    },
    {
      id: 13,
      name: "鲫鱼",
      time: 60,
      money: 0,
      profit: 100,
      reward: 0,
    },
    {
      id: 14,
      name: "鲫鱼",
      time: 60,
      money: 0,
      profit: 100,
      reward: 0,
    },
    {
      id: 15,
      name: "鲫鱼",
      time: 60,
      money: 0,
      profit: 100,
      reward: 0,
    },
  ], //钓鱼时间配置
  kitchenConfigData: {}, //食材加工时间配置
  taskDataConfig:{},
  attendanceConfig:{},
  md5_key: "", //md5密钥
  publicKey: "", //公钥
  token: "", //token
  isSound: 1, //是否开启音效
  isMusic: 1, //是否开启背景音乐
  fishSpeed: 1,
  gameVersion:""
};

const { ccclass, property } = cc._decorator;

@ccclass
export default class GameConfig extends cc.Component {
  init(call = null) {
    this.getGameDataByHttp(call);
  }

  getGameDataByHttp(call) {
    let callback = (err, res)=>{
      if(res.status != 1){
        console.log(`获取游戏数据失败${res}`)
        return
      }
      GameData.fishFarm = res.data.level;
      GameData.nowTask = res.data.task;
      GameData.is_withdraw = res.data.withdraw_num;
      GameData.novice = res.data.novice;
      GameData.fishData = JSON.parse(res.data.fishing_status);
      GameData.redNumber = res.data.re_coupon;
      GameData.money = res.data.banknote;
      GameData.speedUpTimes = res.data.level;
      GameData.isContinuousLogin = res.data.clock_in_num;
      GameData.red_receive_log = res.data.level;
      GameData.piggy_bank_log = res.data.level;
      GameData.ad_conut = res.data.level;
      GameData.offlineTime = res.data.level;
      GameData.kitchenData = res.data.kitchen_status;
      GameData.fish_list = res.data.fish_list;
      GameData.fish_stock = res.data.fish_stock;
      GameData.fish_pond = res.data.fish_pond;
      GameData.fishing_num = res.data.fishing_num;
      GameData.kitchen_stove = res.data.kitchen_stove;
//----------------------------------------------------------------------------
      GameConfigData.orderData = res.data.config.order;
      GameConfigData.fishFarmConfig = res.data.config.order;
      GameConfigData.loginDayNum = res.data.config.order;
      GameConfigData.fishTimeConfig = res.data.config.order;
      GameConfigData.kitchenConfigData = res.data.config.recipe;
      GameConfigData.taskDataConfig = res.data.config.task;
      GameConfigData.attendanceConfig = res.data.config.attendance;
      GameConfigData.kitchenConfigData = res.data.config.order;
      GameConfigData.loginDayNum = res.data.clock_in_num;

      if(call)
      {
          call()
      }
      else
      {
          cc.director.loadScene("Main")
      }
    }

    let data = {
        version: GameConfigData.gameVersion
    }
    HttpMrg.httpRequestByGet("get_game_info", data, callback.bind(this))
  }
}
